package com.guanzhi.validation;

import com.guanzhi.validation.config.ValidatorConfiguration;
import com.guanzhi.validation.domain.User;
import com.guanzhi.validation.service.ValidatorFramework;
import com.guanzhi.validation.service.ValidatorJakarta;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;

/**
 * Spring6
 * <p> Package: com.guanzhi.validation </p>
 * <p> File: UserValidatorTest.java </p>
 * <p> Description:  (使用注解形式 实现validation数据校验 测试类)</p>
 * <p> Date: 2024/9/21 18:31</p>
 *
 * @author LiKai
 * @version 1.0 （代码版本）
 * @email <a href="mailto:Likai55634@aliyun.com">LiKai</a>（邮箱）
 * @date 2024/9/21 18:31
 * @since jdk1.8（jdk版本）
 */
public class UserValidatorTest {

    public void validatorJakarta() {
        // 创建一个 ApplicationContext 对象，用于获取配置文件中的 Bean
        ApplicationContext applicationContext = new AnnotationConfigApplicationContext(ValidatorConfiguration.class);
        // 从 ApplicationContext 中获取 Bean
        ValidatorJakarta validatorJakarta = applicationContext.getBean(ValidatorJakarta.class);
        //创建实例对象
        User user = new User();
        user.setAge(1);
        boolean result = validatorJakarta.validatorJakarta(user);
        System.out.println(result);
    }

    public void validatorFramework() {
        // 创建一个 ApplicationContext 对象，用于获取配置文件中的 Bean
        ApplicationContext applicationContext = new AnnotationConfigApplicationContext(ValidatorConfiguration.class);
        // 从 ApplicationContext 中获取 Bean
        ValidatorFramework validatorFramework = applicationContext.getBean(ValidatorFramework.class);
        //创建实例对象
        User user = new User();
        user.setAge(1);
        boolean result = validatorFramework.validatorFramework(user);
        System.out.println(result);
    }
}
